﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;

namespace ClassLibrary.DAO
{
    public class TblMenuChildDAO
    {
        private DBService _db = null;
        public TblMenuChildDAO(String ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable InsUp(TblMenuChild menuChild, int mode)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("TblMenuChild_InsUP",

                    new string[] { "@IDMenuChild", "@IDMenuParent", "@MenuChildName", "@Mode" },
                    new object[] { menuChild.IDMenuChild, menuChild.IDMenuParent, menuChild.MenuChildName, mode}, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetAllMenuChild()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select a.*, b.MenuParentName from TblMenuChild a, TblMenuParent b where a.IDMenuParent = b.IDMenuParent", false, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetCateChild_ByIDParrent(int IdParrent)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select a.*, b.MenuParentName from TblMenuChild a, TblMenuParent b where a.IDMenuParent = b.IDMenuParent and a.IDMenuParent = @IdParrent",
                        new string[]{"@IdParrent"}, 
                        new object[]{IdParrent},CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
    }
}
